package com.mililoan.common.utils.excel;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.HSSFColor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mililoan.common.utils.DateUtil;
import com.mililoan.common.utils.StackTraceUtil;

@SuppressWarnings("deprecation")
public class AssistUtil {

	private static Logger logger = LoggerFactory.getLogger(AssistUtil.class);

	// 导出excel
	public static OutputStream doExport(String title, String[] headers, String[] columns,
			List<Map<String, Object>> datalist, OutputStream output) throws Exception {
		// ByteArrayOutputStream output = new ByteArrayOutputStream();
		HSSFWorkbook workbook = printExcel(title, headers, columns, datalist);
		if (workbook != null) {
			try {
				workbook.write(output);
				output.flush();
				output.close();
			} catch (Exception e) {
				logger.error("导出excel信息失败:{}", StackTraceUtil.getStackTrace(e));
			}
		}
		return output;
	}

	/**
	 * 导出Excel的方法
	 * 
	 * @param title
	 *            excel中的sheet名称
	 * @param headers
	 *            表头
	 * @param columns
	 *            表头对应的数据库中的列名
	 * @param result
	 *            结果集
	 * @throws Exception
	 */
	private static HSSFWorkbook printExcel(String title, String[] headers, String[] columns,
			List<Map<String, Object>> result) throws Exception {
		// 声明一个工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		boolean b = true;// 判断标题行有没有换行
		try {
			// 创建工作簿实例
			workbook = new HSSFWorkbook();
			// 创建工作表实例
			HSSFSheet sheet = workbook.createSheet(title);
			// 设置列宽
			for (int i = 0; i < headers.length; i++) {
				if ("机构名".equals(headers[i])) {
					sheet.setColumnWidth(i, headers[i].length() * 2000);
				} else if (headers[i].length() > 4) {
					sheet.setColumnWidth(i, 4000);
					b = false;
				} else {
					sheet.setColumnWidth(i, headers[i].length() * 1000);
				}
			}
			// 生成样式
			HSSFCellStyle style = createTitleStyle(workbook);
			// 设置这些样式
			style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
			style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			style.setBorderRight(HSSFCellStyle.BORDER_THIN);
			style.setBorderTop(HSSFCellStyle.BORDER_THIN);
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 标题字体
			HSSFFont font = workbook.createFont();
			font.setColor(HSSFColor.BLACK.index);
			font.setFontHeightInPoints((short) 12);
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示
			font.setFontName("微软雅黑");
			// 把字体应用到当前的样式
			style.setFont(font);

			// 生成样式
			HSSFCellStyle style2 = createTitleStyle(workbook);
			// 设置这些样式
			style2.setFillForegroundColor(HSSFColor.WHITE.index);
			style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
			style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
			style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 集合字体
			HSSFFont listFont = workbook.createFont();
			listFont.setFontHeightInPoints((short) 10);
			listFont.setFontName("微软雅黑");
			// 把字体应用到当前的样式
			style2.setFont(listFont);
			// 产生表格标题行
			HSSFRow row0 = sheet.createRow(0);
			if (b) {
				row0.setHeight((short) 400);
			} else {
				row0.setHeight((short) 600);// 有换行加宽
			}
			for (int i = 0; i < headers.length; i++) {
				HSSFCell cell = row0.createCell(i);
				cell.setCellStyle(style);
				HSSFRichTextString text = new HSSFRichTextString(headers[i]);
				cell.setCellValue(text);
			}

			// 遍历集合数据，产生数据行
			if (result != null) {
				int index = 1;
				if ("从业人员摘要信息".equals(title)) {

					HSSFRow row = sheet.getRow(0);

					style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平布局：居中
					row.getCell(3).setCellValue("转账");
					row.getCell(3).setCellStyle(style);
					row.getCell(7).setCellValue("POS消费");
					row.getCell(7).setCellStyle(style);
					row.getCell(11).setCellValue("现金取");
					row.getCell(11).setCellStyle(style);

					row = sheet.createRow(1);

					row.createCell(3).setCellValue("笔数");
					row.createCell(4).setCellValue("占比(%)");
					row.createCell(5).setCellValue("金额(￥元)");
					row.createCell(6).setCellValue("占比(%)");
					row.createCell(7).setCellValue("笔数");
					row.createCell(8).setCellValue("占比(%)");
					row.createCell(9).setCellValue("金额(￥元)");
					row.createCell(10).setCellValue("占比(%)");
					row.createCell(11).setCellValue("笔数");
					row.createCell(12).setCellValue("占比(%)");
					row.createCell(13).setCellValue("金额(￥元)");
					row.createCell(14).setCellValue("占比(%)");

					sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
					sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
					sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));

					sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 6));
					sheet.addMergedRegion(new CellRangeAddress(0, 0, 7, 10));
					sheet.addMergedRegion(new CellRangeAddress(0, 0, 11, 14));
					index = 2;
				}

				for (Map<String, Object> m : result) {
					HSSFRow row = sheet.createRow(index);
					row.setHeight((short) 350);
					int cellIndex = 0;
					for (String s : columns) {
						HSSFCell cell = row.createCell(cellIndex);
						String[] str = s.split(",");
						HSSFRichTextString richString = null;
						if (str.length == 1) {
							richString = new HSSFRichTextString(m.get(s) == null ? "" : m.get(s).toString());
						} else {
							// DictBean
							// dictBean=HiwanFrameworkBaseUtil.getDictData().get(str[1]);//取缓存中的字典项
							// richString = new HSSFRichTextString(m.get(str[0])
							// == null ? "" :
							// dictBean.getOptionValue(m.get(str[0]).toString()));
						}
						cell.setCellValue(richString);
						cell.setCellStyle(style2);
						cellIndex++;
					}
					index++;
				}
			}
		} catch (Exception e) {
			logger.error("生成导出信息失败:{}", StackTraceUtil.getStackTrace(e));
		}
		return workbook;
	}

	// 设置excel的title样式
	private static HSSFCellStyle createTitleStyle(HSSFWorkbook wb) {
		HSSFFont boldFont = wb.createFont();
		boldFont.setFontHeight((short) 200);
		HSSFCellStyle style = wb.createCellStyle();
		style.setWrapText(true);
		style.setFont(boldFont);
		style.setDataFormat(HSSFDataFormat.getBuiltinFormat("###,##0.00"));
		return style;
	}

	// 设置下载文件中文件的名称
	public static String encodeFilename(String filename, HttpServletRequest request) {
		/**
		 * 获取客户端浏览器和操作系统信息 在IE浏览器中得到的是：User-Agent=Mozilla/4.0 (compatible; MSIE
		 * 6.0; Windows NT 5.1; SV1; Maxthon; Alexa Toolbar)
		 * 在Firefox中得到的是：User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1;
		 * zh-CN; rv:1.7.10) Gecko/20050717 Firefox/1.0.6
		 */
		String agent = request.getHeader("USER-AGENT");
		try {
			if ((agent != null) && (-1 != agent.indexOf("MSIE"))) {
				String newFileName = URLEncoder.encode(filename, "UTF-8");
				newFileName = StringUtils.replace(newFileName, "+", "%20");
				if (newFileName.length() > 150) {
					newFileName = new String(filename.getBytes("GB2312"), "ISO8859-1");
					newFileName = StringUtils.replace(newFileName, " ", "%20");
				}
				return newFileName;
			}
			if ((agent != null) && (-1 != agent.indexOf("Mozilla")))
				return URLEncoder.encode(filename, "UTF-8");

			return filename;
		} catch (Exception ex) {
			return filename;
		}
	}

	/**
	 * 获取Excel中某个单元格的值
	 * 
	 * @param cell
	 * @return
	 * @throws Exception
	 */
	private static String getValue(HSSFCell cell) throws Exception {
		String value = "";
		try {
			DecimalFormat df = new DecimalFormat("#.#########");
			switch (cell.getCellType()) {
				case HSSFCell.CELL_TYPE_NUMERIC: // 数值型
					if (HSSFDateUtil.isCellDateFormatted(cell)) {
						// 如果是date类型则 ，获取该cell的date值
						value = HSSFDateUtil.getJavaDate(cell.getNumericCellValue()).toString();
						java.util.Date date1 = new Date(value);
						SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
						value = format.format(date1);
					} else {// 纯数字 ,保证获取的电话号码不转为科学 计数法
						value = df.format(cell.getNumericCellValue());
					}
					break;
				/* 此行表示单元格的内容为string类型 */
				case HSSFCell.CELL_TYPE_STRING: // 字符串型
					value = cell.getStringCellValue();
					break;
				case HSSFCell.CELL_TYPE_FORMULA:// 公式型
					// 读公式计算值
					value = String.valueOf(cell.getNumericCellValue());
					if (value.equals("NaN")) {// 如果获取的数据值为非法值,则转换为获取字符串
						value = cell.getStringCellValue().toString();
					}
					cell.getCellFormula();
					break;
				case HSSFCell.CELL_TYPE_BOOLEAN:// 布尔
					value = " " + cell.getBooleanCellValue();
					break;
				/* 此行表示该单元格值为空 */
				case HSSFCell.CELL_TYPE_BLANK: // 空值
					value = "";
					break;
				case HSSFCell.CELL_TYPE_ERROR: // 故障
					value = "";
					break;
				default:
					value = cell.getStringCellValue().toString();
			}
		} catch (Exception e) {
			logger.error(StackTraceUtil.getStackTrace(e));
		}
		return value;
	}

	/**
	 * @param fs
	 *            文件路径
	 * @param rowNumber
	 *            从第几行开始读取
	 * @param sheet
	 *            sheet 第一个为1
	 * @return
	 * @throws Exception
	 */
	private static List<String[]> doImport(InputStream fs, int rowNumber, int sheet) throws Exception {
		// String dataStr = "";// 定义集合sms_str用于存Excel中的数据
		String rowStr = "";
		List<String[]> dataStrList = new ArrayList<String[]>();

		sheet = sheet - 1;

		HSSFWorkbook wk = new HSSFWorkbook(fs, true);
		HSSFSheet sh = wk.getSheetAt(sheet);// 得到book第一个工作薄sheet
		int rows = sh.getLastRowNum() + 1 - sh.getFirstRowNum(); // 总行数
		if (rows > 0) {
			for (int r = rowNumber; r < rows; r++) { // 行循环
				HSSFRow row = sh.getRow(r);
				if (row != null) {// 取第一行 && r != 0
					int cells = row.getLastCellNum();// 获得列数
					String[] dataStrs = new String[cells + 1];// 初始化行数组
					dataStrs[0] = String.valueOf(rowNumber + r);// dataStrs[0]为excel的序号
					String cellvalue = null;
					for (int c = 0; c < cells; c++) { // 列循环
						HSSFCell cell = row.getCell(c);
						if (cell != null) {
							// 判断单元格的格式
							if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
								if (HSSFDateUtil.isCellDateFormatted(cell)) {
									cellvalue = DateUtil.getDateString10(cell.getDateCellValue());
								} else {
									cellvalue = getValue(cell);
								}
							} else {
								cellvalue = getValue(cell);
							}
							rowStr += cellvalue.trim() + "|";
							dataStrs[c + 1] = cellvalue.trim();

						} else {
							rowStr += "|";
							dataStrs[c + 1] = "";
						}
					}
					if ("".equals(rowStr.replaceAll("\\|", ""))) {
						break;
					}
					dataStrList.add(dataStrs);
					rowStr = "";
				} else {
					break;
				}
			}
		}

		return dataStrList;
	}

	// 格式化Id
	public static String getFormatId(Integer num, String format) {
		DecimalFormat df = new DecimalFormat(format);
		String numStr = df.format(num);
		return numStr;
	}

	/**
	 * 计算总列数
	 *
	 * @param file
	 * @return
	 */
	@SuppressWarnings("unused")
	public static int conutCellNum(File file) {
		try {
			InputStream fs = new FileInputStream(file);

			HSSFWorkbook wk = new HSSFWorkbook(fs, true);
			HSSFSheet sh = wk.getSheetAt(0);// 得到book第一个工作薄sheet
			int rows = sh.getLastRowNum() + 1 - sh.getFirstRowNum(); // 总行数
			HSSFRow row = sh.getRow(0);
			if (row != null) {// 取第一行 && r != 0
				int cells = row.getLastCellNum();// 获得列数
				return cells;
			}
			return 0;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	/**
	 * 计算总行数
	 *
	 * @param file
	 * @return
	 */
	public static int countRowNum(File file) {
		try {
			InputStream fs = new FileInputStream(file);

			HSSFWorkbook wk = new HSSFWorkbook(fs, true);
			HSSFSheet sh = wk.getSheetAt(0);// 得到book第一个工作薄sheet
			int row = sh.getLastRowNum() + 1 - sh.getFirstRowNum(); // 总行数
			return row;
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	/**
	 * @param fdataFilePath
	 *            文件路径
	 * @param rowNumber
	 *            从第几行开始读取
	 * @return
	 * @throws Exception
	 */
	public List<String[]> doImport(File fdataFilePath, int rowNumber) throws Exception {
		InputStream fs = new FileInputStream(fdataFilePath);
		return doImport(fs, rowNumber, 1);
	}

	// 首页预警信息单元格合并
	public Boolean mergeCells(List<int[]> list, HSSFSheet sheet) {

		int[] cells = null;
		for (int i = 0; i < list.size(); i++) {
			cells = (int[]) list.get(i);
			sheet.addMergedRegion(new CellRangeAddress(cells[0], cells[1], cells[2], cells[3]));// 参数1：起始行；参数2：结束行；参数3：起始列；参数4：结束列
		}
		return true;
	}

	public InputStream export(String title, List<String> list) {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		// 声明一个工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		try {
			// 创建工作簿实例
			workbook = new HSSFWorkbook();
			// 创建工作表实例
			HSSFSheet sheet = workbook.createSheet(title);

			// 生成样式
			HSSFCellStyle style = this.createTitleStyle(workbook);
			// 设置这些样式
			style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
			style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			style.setBorderRight(HSSFCellStyle.BORDER_THIN);
			style.setBorderTop(HSSFCellStyle.BORDER_THIN);
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 标题字体
			HSSFFont font = workbook.createFont();
			font.setColor(HSSFColor.BLACK.index);
			font.setFontHeightInPoints((short) 12);
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示
			font.setFontName("微软雅黑");
			// 把字体应用到当前的样式
			style.setFont(font);

			// 生成样式
			HSSFCellStyle style2 = this.createTitleStyle(workbook);
			// 设置这些样式
			style2.setFillForegroundColor(HSSFColor.WHITE.index);
			style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
			style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
			style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			// 集合字体
			HSSFFont listFont = workbook.createFont();
			listFont.setFontHeightInPoints((short) 10);
			listFont.setFontName("微软雅黑");
			// 把字体应用到当前的样式
			style2.setFont(listFont);
			// 遍历集合数据，产生数据行
			if (list != null) {
				int index = 0;
				for (String m : list) {
					HSSFRow row = sheet.createRow(index);
					row.setHeight((short) 350);
					int cellIndex = 0;
					String[] cellStr = m.split("[|]", -1);
					for (int i = 0; i < cellStr.length; i++) {
						String s = cellStr[i];
						HSSFCell cell = row.createCell(cellIndex);
						cell.setCellValue(s);
						if (index == 0) {
							cell.setCellStyle(style);
							sheet.autoSizeColumn((short) i);
						} else
							cell.setCellStyle(style2);
						cellIndex++;
					}
					index++;
				}
			}
		} catch (Exception e) {
			logger.error("生成导出信息失败:{}", StackTraceUtil.getStackTrace(e));
		}
		if (workbook != null) {
			try {
				workbook.write(output);
				output.flush();
				output.close();
			} catch (Exception e) {
				logger.error("导出excel信息失败:{}", StackTraceUtil.getStackTrace(e));
			}
		}
		return new ByteArrayInputStream(output.toByteArray());
	}

	@SuppressWarnings("unused")
	public byte[] exportBidding(String title, String[] headers, List<Object[]> dataList) {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		// 声明一个工作薄
		HSSFWorkbook workbook = new HSSFWorkbook();
		try {
			// 创建工作簿实例
			workbook = new HSSFWorkbook();
			HSSFSheet sheet = workbook.createSheet(title);

			// 设置列宽
			for (int i = 0; i < headers.length; i++) {
				sheet.setColumnWidth(i, 5000);
			}

			// 生成样式
			HSSFCellStyle styleOne = this.createTitleStyle(workbook);
			// 设置这些样式
			styleOne.setAlignment(HSSFCellStyle.ALIGN_CENTER);

			// 生成样式
			HSSFCellStyle style = this.createTitleStyle(workbook);
			// 设置这些样式
			style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
			style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			style.setBorderRight(HSSFCellStyle.BORDER_THIN);
			style.setBorderTop(HSSFCellStyle.BORDER_THIN);
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
			// 标题字体
			HSSFFont font = workbook.createFont();
			font.setColor(HSSFColor.BLACK.index);
			font.setFontHeightInPoints((short) 12);
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体显示
			font.setFontName("微软雅黑");
			// 把字体应用到当前的样式
			style.setFont(font);

			// 生成样式
			HSSFCellStyle style2 = this.createTitleStyle(workbook);
			// 设置这些样式
			style2.setFillForegroundColor(HSSFColor.WHITE.index);
			style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
			style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			style2.setBorderRight(HSSFCellStyle.BORDER_THIN);
			style2.setBorderTop(HSSFCellStyle.BORDER_THIN);
			style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
			// 集合字体
			HSSFFont listFont = workbook.createFont();
			listFont.setFontHeightInPoints((short) 10);
			listFont.setFontName("微软雅黑");
			// 把字体应用到当前的样式
			style2.setFont(listFont);

			int orderIndex = 0;
			// 产生表格标题行
			HSSFRow row0 = sheet.createRow(orderIndex);
			row0.setHeight((short) 600);
			for (int i = 0; i < headers.length; i++) {
				HSSFCell cell = row0.createCell(i);
				cell.setCellStyle(styleOne);
				cell.setCellValue("");
			}

			orderIndex++;
			HSSFRow row1 = sheet.createRow(orderIndex);
			row1.setHeight((short) 600);
			for (int i = 0; i < headers.length; i++) {
				HSSFCell cell = row1.createCell(i);
				cell.setCellStyle(style);
				HSSFRichTextString text = new HSSFRichTextString(headers[i]);
				cell.setCellValue(text);
			}

			// 行循环处理



			if (CollectionUtils.isEmpty(dataList)) {
				int size = dataList.size();
				int amdr = 0;
				String rSupplyName = ((String[]) dataList.get(0))[0];
				for (int a = 0; a < size; a++) {
					// 继续下级循环
					amdr = 0;
					orderIndex++;
					// 产生表格标题行
					HSSFRow row2 = sheet.createRow(orderIndex);
					row2.setHeight((short) 600);
					String[] rowDetail = (String[]) dataList.get(a);

					// 列循环处理
					boolean isAmdr = false;
					if (null != rowDetail && rowDetail.length != 0) {
						int len = rowDetail.length;
						for (int b = 0; b < len; b++) {
							String rContent = rowDetail[b];
							HSSFCell cell1 = row2.createCell(b);
							cell1.setCellStyle(style2);

							// 校验是否为第一列
							if (b == 0 && !StringUtils.equals(rSupplyName, rContent)) {
								rSupplyName = rContent;
								isAmdr = true;
							}

							if (amdr == 0 && StringUtils.equals(rSupplyName, rContent)) {
								HSSFRichTextString text = new HSSFRichTextString(rSupplyName);
								cell1.setCellValue(text);
							} else {
								rSupplyName = rContent;
								HSSFRichTextString text = new HSSFRichTextString(rContent);
								cell1.setCellValue(text);
							}

							amdr++;

							/*
							 * if (isAmdr) { sheet.addMergedRegion(new
							 * CellRangeAddress( (orderIndex - amdr), 0, (short)
							 * orderIndex, (short) 0)); isAmdr = false; }
							 */
						}
					}
				}
			}

		} catch (Exception e) {
			logger.error("生成导出信息失败:{}", StackTraceUtil.getStackTrace(e));
		}
		if (workbook != null) {
			try {
				workbook.write(output);
				output.flush();
				output.close();
			} catch (Exception e) {
				logger.error("导出excel信息失败:{}", StackTraceUtil.getStackTrace(e));
			}
		}
		return output.toByteArray();
	}
}